<?php


namespace app\admin\controller\business;


use app\common\controller\Adminbase;
use think\Db;

class Ebusiness extends Adminbase
{

    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit) = $this->buildTableParames();
            //获取列表
            $_list = Db::name('shop')
                ->where('status', 'in', [0, 3])    //0待审核 3审核失败
                ->where('is_del', '=', 0)
                ->page($page, $limit)
                ->order('create_time desc')
                ->select();
            foreach ($_list as $k => $v) {
                $_list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
            }
            //获取数量
            $total = Db::name('shop')
                ->where('status', 'in', [0, 3])    //0待审核 3审核失败
                ->where('is_del', '=', 0)
                ->count();
            $result = ["code" => 0, "count" => $total, "data" => $_list];
            return json($result);
        }
        return $this->fetch();
    }

    //审核
    public function verify()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            $insert_data = array(
                'status' => $data['row']['status'],
                'reason_refusal' => $data['row']['reason_refusal'],
                'bank_name' => $data['row']['bank_name'],
                'bank_account' => $data['row']['bank_account'],
                'bank_account_name' => $data['row']['bank_account_name'],
                'finance_people' => $data['row']['finance_people'],
                'finance_phone' => $data['row']['finance_phone'],
            );
            if ($data['row']['status']==1){
                $member_info=Db::name('member')->find($data['member_id']);
                if ($member_info['level_id']<3){
                    Db::name('member')->update([
                        'member_id'=>$data['member_id'],
                        'level_id'=>3,
                    ]);
                }
            }
            $business_info = Db::name('shop')
                ->where('id', '=', $data['id'])
                ->where('is_del', '=', 0)
                ->update($insert_data);
            $this->success('操作成功');
        }
            $business_id = $this->request->param('id/d', 0);
            $data = Db::name('shop')->where('is_del', '=', 0)->where('id', $business_id)->find();
            $data_img=Db::name('shop_img')->where([
                'shop_id'=>$business_id
            ])->select();
            $this->assign([
                'data' => $data,
                'data_img'=>$data_img
            ]);
            return $this->fetch();

    }
}